#ifndef VSCRIPTRENDERTEST_H
#define VSCRIPTRENDERTEST_H

#include <QtGui/QDialog>
#include <QtGui/QSyntaxHighlighter>
#include <QtDeclarative/QDeclarativeEngine>
#include <QtDeclarative/QDeclarativeError>
#include "ui_vscriptrendertest.h"

#include <QtCore/QMap>

class VSimpleHighLighter: public QSyntaxHighlighter
{
	Q_OBJECT

public:
	VSimpleHighLighter(QTextEdit* log, QTextDocument* parent=0);

public Q_SLOTS:
	void currentBlockTest()
	{
		m_log->append(currentBlock().text());
	}

protected:
	virtual void highlightBlock(const QString& text);

private:
	QTextEdit* m_log;
};

class VBlank;
class VStyle;

class QtProperty;
class QtVariantProperty;
class QtVariantPropertyManager;
class QtTreePropertyBrowser;

class QTextEdit;
class VScriptEngine;

class VScriptRenderTest : public QMainWindow
{
	Q_OBJECT

public:
	VScriptRenderTest(QWidget *parent = 0, Qt::WFlags flags = 0);
	~VScriptRenderTest();

private slots:
	void updateEnv();
	bool updateScript();
	void updateRender();	
	void onCursorPosChanged();
	void replaceSelText();
	void fillObjectInspector();

	void objInspItemClicked(QTreeWidgetItem* item, int column);
	void valueChanged(QtProperty *property, const QVariant &value);

	//
	void clickStyleItem(VStyle* style);

	void updateTabScript(int index);

	void qmlParseError(const QList<QDeclarativeError>& warnings);

private:
	void updateExpandState();
	void addProperty(QtVariantProperty *property, const QString &id);

	enum TabIndex
	{
		EScriptEdit=0,
		ETextEdit
	};

private:
	Ui::VScriptRenderTestClass ui;

private:
	QDeclarativeEngine m_engine;
	QDeclarativeComponent* m_component;

	QTextEdit* m_editor;
	QDialog* m_renderDlg;
	VSimpleHighLighter* m_hl;
	QTextEdit* m_scriptEdit;

	QMdiArea* m_mdiArea;
	QTreeWidget* m_objInsp;
	QtTreePropertyBrowser* m_propEditor;
	QtVariantPropertyManager *variantManager;

	QTextEdit* m_log;
	QPushButton* m_btnUpdate;

	VBlank* m_blank;
	VStyle* m_curStyle;

	QMap<QtProperty*, QString> propertyToId;
	QMap<QString, QtVariantProperty*> idToProperty;
	QMap<QString, bool> idToExpanded;

	VScriptEngine* m_scriptEngine;
};

#endif // VSCRIPTRENDERTEST_H
